// 获取product
var shop = document.querySelector("#shopping");
function getUrl(url){
    var urlArr = url.split("?")[1];
    console.log(urlArr)
    urlArr = urlArr.split("&");
    console.log(urlArr);

    var obj = {};
    urlArr.forEach(item =>{
    var itemArr = item.split("=");
    obj[itemArr[0]] = itemArr[1];
    });
    return obj;
}

(function(){
    var urlstyring = decodeURI(location.href);
    console.log(urlstyring);

    let regExp = /(?<=imgurl=)[^'"]*/;
    var pObj = getUrl(urlstyring);
    console.log(pObj);

    const xhr = new XMLHttpRequest();
    xhr.open("get","http://chst.vip:1234/api/getbrandproductlist?brandtitleid="+pObj.brandtitleid,true);
    xhr.send();
    xhr.onreadystatechange = function(){
         if(xhr.readyState === 4 && xhr.status === 200){
            var res = JSON.parse(xhr.responseText);
            console.log(res.result);
            var rex = res.result;
            var ele = "";
            rex.forEach(item => {
                ele += `
                <li class="photo"> 
            <div class="photo_left" productid="${item.productId}">
          ${item.productImg}
    </div> 
     
     <div class="photo_right" productid="${item.productId}">
      
    <div class="photo_right_top" productid="${item.productId}">
      <span productid="${item.productId}">${item.productName}</span>
      <br>
      <span productid="${item.productId}">${item.productPrice}</span>
      </div> 
    
     <div class="photo_right_bottom" productid="${item.productId}">
          <span productid="${item.productId}">${item.productQuote}</span>
          <span>
              <img src="../assets/images/消息.png" alt="">
              <p>${item.productCom}</p>
          </span>
      </div>
      </li> 
                `
            })
           
            shop.innerHTML = ele;
         }
        
    }

shop.onclick = function(event){
    let e = event;
        let target = e.target;
        var _this;
        if(target.nodeName !="IMG"){
            _this = target.parentNode;
        }else{
            _this = target;
        }
        let id = target.getAttribute("productid");
        console.log(id);
        location.href = "../html/十、品牌大全页面详情页.html?productid="+id;  
}
$("gotop").click(function(){
    $("body,html").animate({scrollTop:0},1000);
})
})();